<extend name="Public:base" />
<block name="content">
	<form id="validation-form" method="post">
		<style type="text/css">
			.popuping{
				z-index: 1050;
				width: auto;
				padding: 10px;
				margin-right: auto;
				margin-left: auto;

			}
			.bootbox.fade .popuping{
				-webkit-transform: translate(0,-25%);
				-ms-transform: translate(0,-25%);
				transform: translate(0,-25%);
				-webkit-transition: -webkit-transform .3s ease-out;
				-moz-transition: -moz-transform .3s ease-out;
				-o-transition: -o-transform .3s ease-out;
				transition: transform .3s ease-out;
			}
			.bootbox.in .popuping{
				-webkit-transform: translate(0,0);
				-ms-transform: translate(0,0);
				transform: translate(0,0);
			}
			.bootbox.in .popuping-content{
				position: relative;
				background-color: #fff;
				border: 1px solid #999;
				border: 1px solid rgba(0,0,0,0.2);
				border-radius: 6px;
				outline: 0;
				-webkit-box-shadow: 0 3px 9px rgba(0,0,0,0.5);
				box-shadow: 0 3px 9px rgba(0,0,0,0.5);
				background-clip: padding-box;
				padding: 20px;
				margin: 100px auto 0;
			}
		</style>
		<div class="table-responsive">
			<table class="table table-striped table-bordered table-hover search-form">
				<thead>
			    <th>
					<volist name="detail" id="vo">
						<volist name="vo['orderData']" id="D">
						<span style="margin-right: 20px;">订单号：{$D.repair_order_num_alias}</span>
						<php>if($D['status']!='1'){</php>
						<span style="margin-right: 20px;">支付状态：{$D.pay}</span>
						<php>}</php>
						<span style="margin-right: 20px;">订单状态：{$D.service}</span>
						<span>下单时间：{$D.set_time}</span>
						<php>if($D['book_time']!=0){</php>
						<span> &nbsp;预约时间：{$D.book_time}</span>
						<php>}</php>
						</volist>
					</volist>
				</th>
				</thead>
				<tbody>
					<td style="background-color: #fff;">
						<div class="step-body" id="myStep" style="width:80%;	">
							<div class="step-header">
								<ul>
									<volist name="detail" id="vo">
										<volist name="vo['presentStatus']" id="D">
									<li><p>{$D.Service}<br></p><php>echo $D['time']=='1970-01-01 08:00:00' ?'':$D['time']</php></li>
											<input type="hidden" name="present{$D.Status}" value="{$D.Status}"/>
										</volist>
									</volist>
								</ul>
							</div>
						</div>
						<div style="width:20%; float: left; text-align: center; height: 100%;">
							<!--<volist name="detail" id="vo">-->
							<!--<volist name="vo['orderData']" id="D">-->
									<!--<php>if($D['status']==14 || $D['status']==12){</php>-->
									<!--<a style="margin-bottom: 10px; display: inline-block;" class="btn btn-primary btn-sm radius5" href="{:U('Order/Customer_Services')}/order_id/{:I('order_id')}">客服处理(介入)</a><br>-->
									<!--<php>}</php>-->
							<!--</volist>-->
							<!--</volist>-->
							<!--<php>if($status==refund){</php>-->
							<!--<a style="display: inline-block;" class="btn btn-primary btn-sm radius5" href="{:U('Order/Refund')}" >返回订单列表</a>-->
							<!--<php>}else{</php>-->
							<a style="display: inline-block;" class="btn btn-primary btn-sm radius5" href="{:U('Order/index')}" >返回订单列表</a>
							<!--<php>}</php>-->
						</div>
					</td>
				</tbody>
			</table>
		</div>
	</form>
<div class="row">
	<div class="col-sm-6">
		<div class="table-responsive">
			<table class="table table-striped table-bordered table-hover" id="mytable">
				<tbody>
						<tr>
							<volist name="detail" id="vo">
								<volist name="vo['orderData']" id="D">
								<td>维修项目</td>
								<td>{$D.category_name}</td>
								</volist>
							</volist>
						</tr>
						<tr>
							<td>故障</td>
							<td>
								<ul>
									<volist name="detail" id="vo">
										<volist name="vo['orderFault']" id="F">
									<li>
										<span style="display:inline-block; width: 31%; text-align: left;">{$F.fault_name}</span>
										<span class="color999" style="display:inline-block; width: 31%; text-align: center;">{$F.type}</span>
										<span class="color900" style="display:inline-block; width: 31%;text-align: right;">￥{$F.price}</span>
										<p class="color999 font12">主材￥{$F.material_cost}、耗材￥{$F.deplete_cost}、人工费￥{$F.artificial_cost}</p>
									</li>

										</volist>
									</volist>
									<p class="color999" style="text-align: right;">小计：<em class="color900">￥{$total}</em></p>
								</ul>
								<span class="color999 font12">诊断费￥{$F.diagnosis_cost}</span>
							</td>
						</tr>
						<volist name="detail" id="vo">
							<volist name="vo['orderData']" id="D">
						<tr>
							<td>优惠券</td>
							<td>￥<php>echo empty($D['price'])? 无 :$D['price']</php></td>
						</tr>
						<tr>
							<td>订单金额</td>
							<td>￥{$D.total}</td>
						</tr>
						<php>if($D['status']!='1'){</php>
						<tr>
							<td>维修人员</td>
							<td>{$D.master_name}，{$D.worker_tel} <a href="{:U('User/info')}/user_id/{$D.worker_user_id}&type=master">【查看详细】</a></td>
						</tr>
						<php>if($D['status']=='-2'|| $D['status']>='5'){</php>
						<tr>
							<td>维修金</td>
							<td><em class="color900">￥{$D.maintain}</em></td>
						</tr>
						<tr>
							<td>保证金</td>
							<td><em class="color900">￥{$D.bond}</em>, {$D.count} {$D.unit}到账</td>
						</tr>
						<php>}</php>
						<tr>
							<td>支付状态</td>
							<td class="color999">{$D.pay}</td>
						</tr>
						<php>}</php>
							</volist>
						</volist>
				</tbody>
			</table>
		</div>
	</div>
	<div class="col-sm-6">
		<div class="row">
			<div class="col-xs-12">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover">
						<tbody>
						<volist name="detail" id="vo">
							<volist name="vo['orderData']" id="D">
								<tr>
									<td>业主</td>
									<td>{$D.shipping_name}</td>
								</tr>
								<tr>
									<td>业主电话</td>
									<td>{$D.shipping_tel}</td>
								</tr>
								<tr>
									<td>业主地址</td>
									<td>{$D.shipping_addr} （门牌号）{$D.doorplate}</td>
								</tr>
							</volist>
						</volist>
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover">
						<tbody>
						<volist name="detail" id="vo">
							<volist name="vo['orderStatus']" id="D">
								<tr>
									<td>{$D.add_time}</td>
									<td>{$D.content}
										<php>if($D['reason']){</php>
										<br><span><b>退款理由：</b>{$D.reason}</span>
										<php>}</php>
										<php>if($D['status']==11){</php>

										<php>if($exist){</php>
										<br><b>退款操作：</b>	<button  class="btn btn-xs btn-info radius5" >处理退款</button>
										<php>}else{</php>
										<br><b>退款操作：</b>	<button id="add"  class="btn btn-xs btn-info radius5" >处理退款</button>
										<php>}</php>

										<php>}</php>
										<php>if($D['status']==9 && $D['count']==1){</php>
										<php>if($exist){</php>
										<br><b>客服操作：</b>	<button class="btn btn-xs btn-info radius5" >处理退款</button>
										<php>}else{</php>
										<br><b>客服操作：</b>	<button id ="add" class="btn btn-xs btn-info radius5" >处理退款</button>
										<php>}</php>
										<php>}</php>
									</td>
								</tr>
							</volist>
						</volist>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
	<div class="bootbox modal fade">
		<div class="popuping">
			<div class="popuping-content" style="width: 450px;">
				<div class="ui-jqdialog-content ui-widget-content" id="editcntgrid-table">
					<div>
						<h3>处理退款</h3>
						<form name="FormPost" id="FrmGrid_grid-table" class="FormGrid" onsubmit="return false;" style="width:auto;overflow:auto;position:relative;height:auto;">
							<table id="TblGrid_grid-table" class="EditTable" cellspacing="0" cellpadding="0" border="0">
								<tbody>
								<tr id="FormError" style="display:none">
									<td class="ui-state-error" colspan="2"></td>
								</tr>
								<tr style="display:none" class="tinfo">
									<td class="topinfo" colspan="2"></td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">订单编号：{:I('order_id')}</td>
									<td class="DataTD">&nbsp;
										实收款：¥&nbsp;<span class="receivedMoney">{$received_money}</span>&nbsp;请根据实收款判定
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD"></td>
									<td class="DataTD">&nbsp;
										实付款：¥&nbsp;<span class="paidMoney">{$paid_money}</span>
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">判定给业主：</td>
									<td class="DataTD">&nbsp;
										¥&nbsp;<input style="width: 60px" type="number" class="UserMoney"  name="userMoney" role="textbox" class="FormElement ui-widget-content ui-corner-all">
									</td>
								</tr>
								<tr rowpos="1" class="FormData" id="tr_id">
									<td class="CaptionTD">判定给师傅：</td>
									<td class="DataTD">&nbsp;
										¥&nbsp;&nbsp;<span class="MasterMoney"></span>
									</td>
								</tr>
								<tr rowpos="2" class="FormData" id="tr_sdate">
									<td class="CaptionTD">填写备注：</td><br>
									<td class="DataTD">&nbsp;
										<input style="width: 300px" type="text"  name="record" role="textbox" class="FormElement ui-widget-content ui-corner-all">
									</td>
								</tr>
								</tbody>
							</table>
						</form>
						<div style="text-align: center;">
							<button class="btn btn-xs btn-info radius5 marginT10" id="save">确定</button>
							<button class="btn btn-xs btn-info radius5 marginT10" style="margin-left: 100px;" id="cancel">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="javascript">
<script>
$(function(){

	$("#search").click(function () {
        var url = $(this).attr('url');
        var query = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
        query = query.replace(/^&/g, '');
        if (url.indexOf('?') > 0) {
            url += '&' + query;
        } else {
            url += '?' + query;
        }
        window.location.href = url;
    });

		$value1 = $("input[name=present1]").val();
		$value2 = $("input[name=present2]").val();
		$value3 = $("input[name=present3]").val();
		$value4 = $("input[name=present4]").val();
		$value0 = $("input[name=present-1]").val();


		if($value4){
			var step= $("#myStep").step({
				animate:true,
				initStep:4,
				speed:1000
			});
		}else if($value3){
		var step= $("#myStep").step({
			animate:true,
			initStep:3,
			speed:1000
		});
		}else if($value2){
		var step= $("#myStep").step({
			animate:true,
			initStep:2,
			speed:1000
		});
		}else if($value0) {
			var step = $("#myStep").step({
				animate: true,
				initStep: 2,
				speed: 1000
			});
		}else if($value1){
			var step = $("#myStep").step({
				animate: true,
				initStep: 1,
				speed: 1000
			});
		}

	$('#add').click(function(){
		$("body").append("<div class=\"modal-backdrop fade in\"></div>");
		$(".bootbox.modal.fade").addClass("in").show(400);
	});

	$('#cancel').click(function(){
		$(".bootbox.modal.fade").addClass("in").hide(400);
		setTimeout(function(){
			$(".modal-backdrop.fade.in").remove()
		},200);
	});

	$(".UserMoney").blur(function(){
		var received = Number($(".receivedMoney").html()); //应收款
		var paid = Number($('.paidMoney').html()); //实收款

		var user = Number($('.UserMoney').val()); //业主退的款
		var master = received-user;
		if(user == 0) {
			var master = received;       //师傅退的款
		}
		if(master==0){
			$('.UserMoney').val(paid);
		}
		$(".MasterMoney").html(master.toFixed(2));
	});

	$("#save").click(function(){
		var user_money	 = Number($(".UserMoney").val());
		var master_money = Number($(".MasterMoney").html());
		if(user_money==0){
			var total  = Number($(".receivedMoney").html());
		}
		if(master_money==0){
			var total = Number($('.paidMoney').html());
		}
		var remark = $("input[name=record]").val();

		var temp=/^\d+(\.\d+)?$/;
		if (temp.test(user_money) == false) {
			$.jbox.info('金额不能为负数', '提示');
			return false;
		}

		if(temp.test(master_money)==false){
			$.jbox.info('请输入正确数字','提示');
			return false;
		}

		if(user_money=='' && master_money==''){
			$.jbox.info('请输入退款金额！','提示');
			return false;
		}

		$.ajax({
			url:"{:U('Order/addToRefundMoney')}",
			type:"post",
			data:{
				total : total,
				user_money: user_money,
				master_money:master_money,
				order_id:"{:I('order_id')}",
				remark: remark
			},
			success:function(data){
				if(data=='1'){
					$.jbox.tip("处理成功！", 'loading');
					window.setTimeout(function () {window.location.reload() }, 500);
				}else if(data=='3'){
					$.jbox.info("您已处理过该订单！",'提示');
				}else{
					$.jbox.info("处理失败！",'提示');
				}
			}
		})

	});



});
</script>
</block>